package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @Title: UploadController
 * @Package: com.project.controller
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/6/30 - 14:07
 */
@SuppressWarnings("all")
//文件上传控制器
@RestController
public class UploadController {
    @RequestMapping("upload")
    public String upload(@RequestParam("uploadImg") MultipartFile mf) throws IOException {
//        得到上传文件的名称
        var fileName=mf.getOriginalFilename();
//        以毫秒数来重命名文件，防止重复
        fileName=System.currentTimeMillis()+fileName.substring(fileName.lastIndexOf("."));
//        将文件二进制数据写入指定文件
        mf.transferTo(new File("D:\\JavaPlus\\javaWEB\\Employee\\employeeFaceImg/"+fileName));

        return fileName;
    }
}
